package com.linkwin.updater.util;

import java.util.Calendar;

public class TimeCheckUtil {

    public static boolean isTimeInRange(int startHour, int startMinute, int endHour, int endMinute) {

        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        int currentHour = calendar.get(Calendar.HOUR_OF_DAY); // 24小时制
        int currentMinute = calendar.get(Calendar.MINUTE);

        // 计算当前时间的总分钟数（方便比较）
        int currentTimeInMinutes = currentHour * 60 + currentMinute;
        int startTimeInMinutes = startHour * 60 + startMinute;
        int endTimeInMinutes = endHour * 60 + endMinute;

        // 判断是否在范围内（支持跨天情况，如 23:00 - 01:00）
        if (startTimeInMinutes <= endTimeInMinutes) {
            return currentTimeInMinutes >= startTimeInMinutes
                    && currentTimeInMinutes <= endTimeInMinutes;
        } else {
            return currentTimeInMinutes >= startTimeInMinutes
                    || currentTimeInMinutes <= endTimeInMinutes;
        }

    }

}
